package com.bbyb.operating.examination.controller;

import com.bbyb.operating.examination.model.vo.CommonResult;
import com.bbyb.operating.examination.service.RoleService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bbyb.operating.examination.model.po.Role;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName: RoleController
 * @Description: 角色基础新增
 * @Author: ZengFz
 * @Date: 2024/5/1 11:57:27
 */
@Api(tags = "角色控制")
@RestController
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 新增角色
     *
     * @param role 要新增的角色信息
     * @return ResponseEntity<Void> 返回创建成功的状态码
     */
    @PostMapping("/roles")
    @ApiOperation("新增角色")
    public CommonResult<String> addRole(@RequestBody Role role) {
        // 调用服务层新增角色方法
        roleService.addRole(role);
        // 返回创建成功的状态码
        return new CommonResult<>();
    }

    /**
     * 删除角色
     *
     * @param roleId 要删除的角色ID
     * @return ResponseEntity<Void> 返回删除操作的状态码或异常信息
     */
    @DeleteMapping("/roles/{roleId}")
    @ApiOperation("删除角色")
    public CommonResult<String> deleteRole(@PathVariable Integer roleId) {
        // 执行角色删除操作
        roleService.deleteRole(roleId);
        // 返回删除成功的状态码
        return new CommonResult<>();
    }


}
